package com.otitan.forest.right.config;

import com.alibaba.fastjson.JSON;
import org.apache.shiro.web.filter.authc.UserFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 当前类作用描述
 * @Author: xiazw
 * @CreateDate: 2020/8/5 17:55
 */
public class ShiroUserConfig extends UserFilter {
    @Override
    protected void redirectToLogin(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException {
        // 返回json
        servletResponse.setContentType("application/json; charset=utf-8");

        Map<String, Object> response = new HashMap<String, Object>();
        response.put("code", 401);
        response.put("msg", "未登录或者登录已失效");

        String json = JSON.toJSONString(response);

        servletResponse.getWriter().write(json);
    }
}
